<!--
- Author:   .
- Date:    2017/7/15 0015.
- File:    message.
-->
<template>
  <div class="Web_Box">
    <div class="newlist"
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="false"
      infinite-scroll-distance="0"
      infinite-scroll-immediate-check="false">
      <ul>
        <li v-for="item in noticeList.data" @click="gotoDetail(item.msg_id)">
          <p class="text3">{{item.title}}</p>
          <p class="time" style="padding: 0">{{item.add_time | timestampToDate}}</p>
        </li>
      </ul>
      <empty-data :show="noticeList.requested && noticeList.data.length <= 0"></empty-data>
    </div>
    <loading-more :allLoaded="noticeList.allLoaded" :show="noticeList.data.length > 0"></loading-more>
    <footer-tab></footer-tab>
  </div>
</template>

<script>
  export default{
    data() {
      return {
        noticeList: {requested: false, allLoaded: false, data: [], page: '1', pageSize: '10'}
      }
    },
    created() {
      this.getMemberNoticeList()
    },
    methods: {
      getMemberNoticeList() {
        this.noticeList.loading = true
        this.$request.getMemberNoticeList(this.noticeList.page, this.noticeList.pageSize).then(data => {
          if (data.length < this.noticeList.pageSize) {
            this.noticeList.allLoaded = true
          }
          this.noticeList.data = [...this.noticeList.data, ...data]
        }).finally(() => {
          this.noticeList.loading = false
          this.noticeList.requested = true
        })
      },
      loadMore() {
        if (this.noticeList.loading || this.noticeList.allLoaded) { // 正在加载 或 已取得全部数据
          return
        }
        setTimeout(() => {
          this.getMemberNoticeList(this.type, ++this.noticeList.page, this.noticeList.pageSize)
        }, 500)
      },
      gotoDetail(id) {
        this.$router.push({name: 'member-notice-detail', params: {id: id}})
      }
    }
  }
</script>

<style>

</style>